package Com.Hupochuan.Dal.Tab;

import java.util.Hashtable;

import Com.Hupochuan.Dal.DBManager.DBManager;
import Com.Hupochuan.Vo.PageMovieList;

public class PageMovieListTab {
	/*
	 * 本类私有对象
	 */
	private DBManager<PageMovieList> dbManager = new DBManager<PageMovieList>(PageMovieList.class);
	
	/*
	 * 单一实例
	 */
	private PageMovieListTab(){}
	private static PageMovieListTab pageMovieListTab = new PageMovieListTab();
	public static PageMovieListTab getObject(){
		return pageMovieListTab;
	}
	
	/*
	 * 添加数据
	 */
	public int appendData(long yearId,long areaSortId,long typeId,long directorId,long actorId,long pageNo){
		
		//参数部分
		StringBuffer sqlBuff = new StringBuffer();
		Hashtable<String,Object> paraHash = new Hashtable<String,Object>();
		
		//sql语句部分
		sqlBuff.append(" insert into PageMovieList set ");
		sqlBuff.append(" 	yearId=${yearId}, ");
		sqlBuff.append(" 	areaSortId=${areaSortId}, ");
		sqlBuff.append(" 	typeId=${typeId}, ");
		sqlBuff.append(" 	directorId=${directorId}, ");
		sqlBuff.append(" 	actorId=${actorId}, ");
		sqlBuff.append(" 	pageNo=${pageNo}, ");
		sqlBuff.append(" 	createTime=now(), ");
		sqlBuff.append(" 	updateTime=now() ");
		
		//sql参数部分
		paraHash.put("yearId",yearId);
		paraHash.put("areaSortId",areaSortId);
		paraHash.put("typeId",typeId);
		paraHash.put("directorId",directorId);
		paraHash.put("actorId",actorId);
		paraHash.put("pageNo",pageNo);
		
		//执行sql 并返回参数
		return dbManager.updateSql(sqlBuff.toString(),paraHash);
	}
	
	/*
	 * 根据电影ID 更新数据
	 */
	public int updateData(String url,long yearId,long areaSortId,long typeId,long directorId,long actorId,long pageNo){
		//参数部分
		StringBuffer sqlBuff = new StringBuffer();
		Hashtable<String,Object> paraHash = new Hashtable<String,Object>();
		
		//sql语句部分
		sqlBuff.append(" update PageMovieList set ");
		sqlBuff.append(" url=${url}, ");
		sqlBuff.append(" isUpdate=0, ");
		sqlBuff.append(" updateTime=now() ");
		sqlBuff.append(" where yearId=${yearId} ");
		sqlBuff.append(" 	and areaSortId=${areaSortId} ");
		sqlBuff.append(" 	and typeId=${typeId} ");
		sqlBuff.append(" 	and directorId=${directorId} ");
		sqlBuff.append(" 	and actorId=${actorId} ");
		sqlBuff.append(" 	and pageNo=${pageNo} ");
		
		//sql参数部分
		paraHash.put("url",url);
		paraHash.put("yearId",yearId);
		paraHash.put("areaSortId",areaSortId);
		paraHash.put("typeId",typeId);
		paraHash.put("directorId",directorId);
		paraHash.put("actorId",actorId);
		paraHash.put("pageNo",pageNo);
		
		//执行sql 并返回参数
		return dbManager.updateSql(sqlBuff.toString(),paraHash);
	}
	
	/*
	 * 获得页面电影对象
	 */
	public PageMovieList findPageMovieList(long yearId,long areaSortId,long typeId,long directorId,long actorId,long pageNo){
		//参数部分
		PageMovieList pageMovieList = null;
		StringBuffer sqlBuff = new StringBuffer();
		Hashtable<String,Object> paraHash = new Hashtable<String,Object>();
		
		//sql语句部分
		sqlBuff.append(" select * from PageMovieList ");
		sqlBuff.append(" where yearId=${yearId} ");
		sqlBuff.append(" 	and areaSortId=${areaSortId} ");
		sqlBuff.append(" 	and typeId=${typeId} ");
		sqlBuff.append(" 	and directorId=${directorId} ");
		sqlBuff.append(" 	and actorId=${actorId} ");
		sqlBuff.append(" 	and pageNo=${pageNo} ");
		
		//sql参数部分
		paraHash.put("yearId",yearId);
		paraHash.put("areaSortId",areaSortId);
		paraHash.put("typeId",typeId);
		paraHash.put("directorId",directorId);
		paraHash.put("actorId",actorId);
		paraHash.put("pageNo",pageNo);
		
		//从列表中获得对象
		pageMovieList = dbManager.querySqlReturnVo(sqlBuff.toString(),paraHash);
		
		//返回
		return pageMovieList;
	}
}
